if &compatible
  set nocompatible
endif

let $VIMPATH = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let $VARPATH = expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache').'/vim')

" Constants
let s:is_sudo = $SUDO_USER !=# '' && $USER !=# $SUDO_USER

function! s:source_rc(path, ...) abort
  let use_global = get(a:000, 0, !has('vim_starting'))
  let abspath = resolve(expand($VIMPATH.'/core/' . a:path))
  if !use_global
    execute 'source' fnameescape(abspath)
    return
  endif

  " substitute all 'set' to 'setglobal'
  let content = map(readfile(abspath),
        \ 'substitute(v:val, "^\\W*\\zsset\\ze\\W", "setglobal", "")')
  " create tempfile and source the tempfile
  let tempfile = tempname()
  try
    call writefile(content, tempfile)
    execute 'source' fnameescape(tempfile)
  finally
    if filereadable(tempfile)
      call delete(tempfile)
    endif
  endtry
endfunction

augroup MyAutoCmd
	autocmd!
	autocmd CursorHold *? syntax sync minlines=300
augroup END

if has('vim_starting')
  call s:source_rc('init.vim')
endif

call s:source_rc('deinrc.vim')
call s:source_rc('plugins/allkey.vim')

syntax enable
filetype plugin indent on

call dein#call_hook('source')
call dein#call_hook('post_source')

" Loading configuration modules
call s:source_rc('general.vim')
call s:source_rc('filetype.vim')
call s:source_rc('mappings.vim')
call s:source_rc('/themes/theme.vim')
"---------------------------------------------------------------------------

set secure

" vim: foldmethod=marker
" vim: set ts=2 sw=2 tw=80 noet :
